package com.oilsection.demo.controller;

import com.oilsection.demo.controller.req.ZrEventImportReq;
import com.oilsection.demo.controller.req.ZrEventPageQueryReq;
import com.oilsection.demo.controller.req.ZrEventUpdateReq;
import com.oilsection.demo.controller.res.ZrEventPageQueryResponse;
import com.oilsection.demo.po.ZrEvent;
import com.oilsection.demo.service.ZrEventService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/zrEvent")
@RequiredArgsConstructor
@Slf4j
public class ZrEventController {
    private final ZrEventService zrEventService;

    @PostMapping("/getZrEventPage")
    @CrossOrigin
    public ZrEventPageQueryResponse getZrEventPage(@RequestBody ZrEventPageQueryReq req) {
        req.setPage(req.getPage() + 1);
        log.info("getZrEventPage req:{}", req);
        ZrEventPageQueryResponse zrEventPage = zrEventService.getZrEventPage(req);
        log.info("getZrEventPage res:{}", zrEventPage);
        System.out.println(zrEventPage.getZrEventList());
        System.out.println(zrEventPage.getZrEventList().size());
        return zrEventPage;
    }

    @PostMapping("import")
    @CrossOrigin
    public void importZrEvent(@RequestBody List<ZrEventImportReq> reqs) {
        log.info("importZrEvent req:{}", reqs);
        zrEventService.importZrEvent(reqs);
    }

    // 根据id删除
    @PostMapping("/deleteById/{id}")
    @CrossOrigin
    public boolean deleteZrEvent(@PathVariable Long id) {
        log.info("deleteZrEvent id:{}", id);
        zrEventService.deleteZrEventById(id);
        return true;
    }

    // 根据id更新
    @PostMapping("/updateById")
    @CrossOrigin
    public boolean updateZrEvent(@RequestBody ZrEventUpdateReq req) {
        log.info("updateZrEvent zrEvent:{}", req);
        zrEventService.updateZrEventById(req);
        return true;
    }
}
